/**
 * Created by lenovo on 2018/1/9.
 */
define(['ngApp', 'ngHttp', 'jquery', 'ngConstant', 'ngAlert', 'bootstrap'], function (ngApp, ngHttp, JQ, ngConstant, ngAlert) {
    ngApp.controller("leftTab9", function ($scope, $http, $timeout, $rootScope, $state, $uibModal, commonFn, $cookies, $window, Upload) {
        $('#tabBoxH').height($('.tab-content').height());

        //获取默认的
        $http({
            url: ngConstant.interfaceHost + 'admin/pic/findAllPic',
            method: 'GET',
            // data: JSON.stringify(obj),
            headers: {'Authorization': $cookies.get("token")}
        }).then(function (res) {
            $scope.advArr = res.data.data;
            // for(var i = 0; i < res.data.data.length; i++) {
            //     $scope.advArr[i].picPath = ngConstant.interfaceHost + res.data.data[i].picPath;
            // }

        }, function () {

        });




        $scope.setSlider1 = function (file) {
            file.upload = Upload.upload({
                url: ngConstant.interfaceHost + 'manager/pic/uploadFile',
                type: "POST",
                data: {
                    'file': file
                },
                headers: {'Authorization': $cookies.get("token")}
            });
            file.upload.then(function (response) {
                console.log(response);
                $scope.advArr[0].picPath = ngConstant.interfaceHost + response.data.data;
                console.log($scope.advArr[0].picPath);
                // $scope.src = ngConstant.interfaceHost + response.data.data;
            }, function (evt) {
                console.log(evt);
            });
        };

        $scope.saveSlider1 = function () {
            var obj = {};
            obj.picPath = $scope.advArr[0].picPath;
            obj.title = $scope.advArr[0].title;
            obj.content = $scope.advArr[0].content;
            obj.id = $scope.advArr[0].id;
            $http({
                url: ngConstant.interfaceHost + 'manager/pic/createMsgInfo',
                method: 'POST',
                data: JSON.stringify(obj),
                headers: {'Authorization': $cookies.get("token")}
            }).then(function (res) {
                ngAlert.successMsg(res.data.data);
            }, function () {
                ngAlert.errorMsg('广告创建失败');
            });
        };


        $scope.setSlider2 = function (file) {
            file.upload = Upload.upload({
                url: ngConstant.interfaceHost + 'manager/pic/uploadFile',
                type: "POST",
                data: {
                    'file': file
                },
                headers: {'Authorization': $cookies.get("token")}
            });
            file.upload.then(function (response) {
                console.log(response);
                $scope.advArr[1].picPath = ngConstant.interfaceHost + response.data.data;
                console.log($scope.advArr[1].picPath);
                // $scope.src = ngConstant.interfaceHost + response.data.data;
            }, function (evt) {
                console.log(evt);
            });
        };


        $scope.saveSlider2 = function () {
            var obj = {};
            obj.picPath = $scope.advArr[1].picPath;
            obj.title = $scope.advArr[1].title;
            obj.content = $scope.advArr[1].content;
            obj.id = $scope.advArr[1].id;
            console.log(obj);
            $http({
                url: ngConstant.interfaceHost + 'manager/pic/createMsgInfo',
                method: 'POST',
                data: JSON.stringify(obj),
                headers: {'Authorization': $cookies.get("token")}
            }).then(function (res) {
                ngAlert.successMsg(res.data.data);
            }, function () {
                ngAlert.errorMsg('广告创建失败');
            });
        };



        $scope.setSlider3 = function (file) {
            file.upload = Upload.upload({
                url: ngConstant.interfaceHost + 'manager/pic/uploadFile',
                type: "POST",
                data: {
                    'file': file
                },
                headers: {'Authorization': $cookies.get("token")}
            });
            file.upload.then(function (response) {
                console.log(response);
                $scope.advArr[2].picPath = ngConstant.interfaceHost + response.data.data;
                console.log($scope.advArr[2].picPath);
                // $scope.src = ngConstant.interfaceHost + response.data.data;
            }, function (evt) {
                console.log(evt);
            });
        };






        $scope.saveSlider3 = function () {
            var obj = {};
            obj.picPath = $scope.advArr[2].picPath;
            obj.title = $scope.advArr[2].title;
            obj.content = $scope.advArr[2].content;
            obj.id = $scope.advArr[2].id;
            console.log(obj);
            $http({
                url: ngConstant.interfaceHost + 'manager/pic/createMsgInfo',
                method: 'POST',
                data: JSON.stringify(obj),
                headers: {'Authorization': $cookies.get("token")}
            }).then(function (res) {
                ngAlert.successMsg(res.data.data);
            }, function () {
                ngAlert.errorMsg('广告创建失败');
            });
        };








    })
});